package com.gree.auth.controller;

import com.gree.common.annotation.Log;
import com.gree.common.entity.ReturnVo;
import com.gree.common.enums.BusinessType;
import com.gree.framework.entity.SysClient;
import com.gree.framework.service.SysClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 180686 on 2021/6/15 14:51
 */

@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private SysClientService sysClientService;

    /**
     * 新建租户
     * @return
     */
    @Log(title = "租户Client日志", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody SysClient sysClient){
        sysClientService.addSysClient(sysClient);
        return new ReturnVo("200","success");
    }

    /**
     * 显示租户
     * @return
     */
    @GetMapping("/list")
    public Object list(SysClient sysClient){
        List<SysClient> list = sysClientService.selectSysClient(sysClient);
        return new ReturnVo("200","success", list);
    }

    /**
     * 修改租户
     */
    @Log(title = "租户Client日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public ReturnVo edit(@RequestBody SysClient sysClient)
    {
        int resultNum = sysClientService.updateSysClient(sysClient);
        if(resultNum > 0){
            return new ReturnVo("200","success");
        }else{
            return new ReturnVo("500","fail");
        }
    }

    /**
     * 删除租户
     */
    @Log(title = "租户Client日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{clientid}")
    public ReturnVo remove(@PathVariable("clientid") String clientid)
    {
        int resultNum = sysClientService.deleteSysClientById(clientid);
        if(resultNum > 0){
            return new ReturnVo("200","success");
        }else{
            return new ReturnVo("500","fail");
        }
    }

    /**
     * 重置租户
     */
    @Log(title = "租户Client日志", businessType = BusinessType.INSERT)
    @GetMapping("/reset/{clientid}")
    public Object reset(@PathVariable("clientid") String clientid){
        int resultNum = sysClientService.resetPassword(clientid);
        if(resultNum > 0){
            return new ReturnVo("200","success");
        }else{
            return new ReturnVo("500","fail");
        }
    }
    
}
